<?php

	// TITLE: Volunteer AUTO MODEL
	// FILE: scaffolding/model/volunteer.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createVolunteer = function($con, $volunteer) {
		$sql = 'INSERT INTO volunteer (id, consent_age, consent_video, consent_waiver, consent_photo, avail_day, avail_eve, avail_weekend, when_age, when_video, when_waiver, when_photo) VALUES (';
		$sql .= $volunteer->getId() . ', ';
		$sql .= $volunteer->getConsentAge() . ', ';
		$sql .= $volunteer->getConsentVideo() . ', ';
		$sql .= $volunteer->getConsentWaiver() . ', ';
		$sql .= $volunteer->getConsentPhoto() . ', ';
		$sql .= $volunteer->getAvailDay() . ', ';
		$sql .= $volunteer->getAvailEve() . ', ';
		$sql .= $volunteer->getAvailWeekend() . ', ';
		$sql .= $volunteer->getWhenAge() . ', ';
		$sql .= $volunteer->getWhenVideo() . ', ';
		$sql .= $volunteer->getWhenWaiver() . ', ';
		$sql .= $volunteer->getWhenPhoto() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readVolunteer = function($con, $id) {
		$sql = 'SELECT * FROM volunteer WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$volunteer = new Volunteer();
			$volunteer->setId(result[0]);
			$volunteer->setConsentAge(result[1]);
			$volunteer->setConsentVideo(result[2]);
			$volunteer->setConsentWaiver(result[3]);
			$volunteer->setConsentPhoto(result[4]);
			$volunteer->setAvailDay(result[5]);
			$volunteer->setAvailEve(result[6]);
			$volunteer->setAvailWeekend(result[7]);
			$volunteer->setWhenAge(result[8]);
			$volunteer->setWhenVideo(result[9]);
			$volunteer->setWhenWaiver(result[10]);
			$volunteer->setWhenPhoto(result[11]);
		} else {
			$volunteer = false;
		}
		return $volunteer;
	};

	$updateVolunteer = function($con, $volunteer) {
		$sql = 'UPDATE volunteer SET ';
		$sql .= 'id = ' . $volunteer->getId() . ', ';
		$sql .= 'consent_age = ' . $volunteer->getConsentAge() . ', ';
		$sql .= 'consent_video = ' . $volunteer->getConsentVideo() . ', ';
		$sql .= 'consent_waiver = ' . $volunteer->getConsentWaiver() . ', ';
		$sql .= 'consent_photo = ' . $volunteer->getConsentPhoto() . ', ';
		$sql .= 'avail_day = ' . $volunteer->getAvailDay() . ', ';
		$sql .= 'avail_eve = ' . $volunteer->getAvailEve() . ', ';
		$sql .= 'avail_weekend = ' . $volunteer->getAvailWeekend() . ', ';
		$sql .= 'when_age = ' . $volunteer->getWhenAge() . ', ';
		$sql .= 'when_video = ' . $volunteer->getWhenVideo() . ', ';
		$sql .= 'when_waiver = ' . $volunteer->getWhenWaiver() . ', ';
		$sql .= 'when_photo = ' . $volunteer->getWhenPhoto() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteVolunteer = function($con, $id) {
		$sql = 'DELETE FROM volunteer WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listVolunteer = function($con) {
		$sql = 'SELECT * FROM volunteer';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$volunteers = array();
			while ($result = mysqli_fetch_array($results)) {
				$volunteer = new Volunteer();
				$volunteer->setId(result[0]);
				$volunteer->setConsentAge(result[1]);
				$volunteer->setConsentVideo(result[2]);
				$volunteer->setConsentWaiver(result[3]);
				$volunteer->setConsentPhoto(result[4]);
				$volunteer->setAvailDay(result[5]);
				$volunteer->setAvailEve(result[6]);
				$volunteer->setAvailWeekend(result[7]);
				$volunteer->setWhenAge(result[8]);
				$volunteer->setWhenVideo(result[9]);
				$volunteer->setWhenWaiver(result[10]);
				$volunteer->setWhenPhoto(result[11]);
				$volunteers[] = volunteer;
			}// end while
		} else {
			$volunteers = false;
		}
		return $volunteers;
	};

